package com.sfh.base.ui;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import com.sfh.base.mvp.ILifeCycle;
import com.sfh.base.mvp.IPresenter;


/**
 * 功能描述:MVP【不存在任何业务逻辑代码】
 *
 * @date 2017/7/5
 */
public abstract class UIMVPFragment extends UIStyleFragment {

    /**
     * 创建UI请求控制对象
     */
    public abstract IPresenter createPresenter();

    //每个Activity对应一个请求控制
    protected IPresenter presenter = null;

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {

        super.onViewCreated (view, savedInstanceState);
        this.presenter = createPresenter ();
        if (this.presenter != null) {
            this.presenter.onLifecycleEvent (this, ILifeCycle.Event.ON_CREATE);
        }

    }

    @Override
    public void onStart() {

        super.onStart ();
        if (this.presenter != null) {
            this.presenter.onLifecycleEvent (this, ILifeCycle.Event.ON_START);
        }
    }

    @Override
    public void onResume() {

        super.onResume ();
        if (this.presenter != null) {
            this.presenter.onLifecycleEvent (this, ILifeCycle.Event.ON_RESUME);
        }
    }

    @Override
    public void onPause() {

        super.onPause ();
        if (this.presenter != null) {
            this.presenter.onLifecycleEvent (this, ILifeCycle.Event.ON_PAUSE);
        }
    }


    @Override
    public void onStop() {

        super.onStop ();
        if (this.presenter != null) {
            this.presenter.onLifecycleEvent (this, ILifeCycle.Event.ON_STOP);
        }
    }

    @Override
    public void onDestroyView() {

        if (this.presenter != null) {
            this.presenter.onLifecycleEvent (this, ILifeCycle.Event.ON_FINISH);
        }
        super.onDestroyView ();
    }

}
